//
//  HJUpdateVC.m
//  project
//
//  Created by hu on 2019/4/1.
//  Copyright © 2019 健健. All rights reserved.
//

#import "HJUpdateVC.h"

@interface HJUpdateVC ()

/**
 头部背景
 */
@property (weak, nonatomic) IBOutlet UIImageView *bgImgeView;
/**
 版本号
 */
@property (weak, nonatomic) IBOutlet UILabel *vsersionLabel;
/**
 最新版本+版本号
 */
@property (weak, nonatomic) IBOutlet UILabel *version;

/**
 版本包大小
 */
@property (weak, nonatomic) IBOutlet UILabel *version_size;

/**
 更新内容
 */
@property (weak, nonatomic) IBOutlet UILabel *update_content;

/**
 底部视图切圆角
 */
@property (weak, nonatomic) IBOutlet UIView *btmView;

@property (weak, nonatomic) IBOutlet UIButton *cancelBtn;

@property (nonatomic,strong) NSDictionary * dataDic;
@end

@implementation HJUpdateVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.vsersionLabel rounded:UIRectCornerAllCorners radius:10];
    [self.bgImgeView rounded:(UIRectCornerTopLeft | UIRectCornerTopRight) radius:10];
    [self.btmView rounded:(UIRectCornerBottomLeft | UIRectCornerBottomRight) radius:10];
    
}
#pragma mark -- 给UI赋值
-(void)updateLoadDataWithDic:(NSDictionary *)dic {
    _dataDic = dic;
    self.vsersionLabel.text = [NSString stringWithFormat:@"V%@",dic[@"version"]];
    self.version.text = [NSString stringWithFormat:@"最新版本：V%@",dic[@"version"]];
    self.version_size.text = [NSString stringWithFormat:@"最新版本大小：%@M",dic[@"size"]];
    self.update_content.text = dic[@"content"];
    if ([dic[@"status"] intValue]==1) {
        self.cancelBtn.hidden = YES;
    }else {
        self.cancelBtn.hidden = NO;
    }
    [self.view layoutIfNeeded];
}

- (IBAction)updateBtnClicked:(UIButton *)sender {
    NSURL * url = [NSURL URLWithString:_dataDic[@"url"]];
    if (@available(iOS 10.0, *)) {
        [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
    } else {
        [[UIApplication sharedApplication] openURL:url];
    }
}

- (IBAction)closeBtn:(id)sender {
    [self.view removeFromSuperview];
}

@end
